package org.nichao.controll;

import com.github.pagehelper.PageInfo;
import org.nichao.pojo.Foodinfo;
import org.nichao.pojo.Parames;
import org.nichao.service.FoodrinfoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/**
 * @ClassName UserinfoController
 * @Description: TODO
 * @Author 44401
 * @Date 2020/4/15
 * @Version V1.0
 **/
@Controller
public class FoodinfoController {

    //业务数据
    @Resource
    private FoodrinfoService foodrinfoService;

    //list0.jsp
//    @RequestMapping("/list")
//    public String list(ModelMap map){
//
//        //业务方法
//        List<Userinfo> list= userinfoService.all();
//
//        //保存数据
//        map.addAttribute("list",list);
//
//        //转发
//        return "list";  //list.jsp
//    }


    @RequestMapping("/find")
    public String find(ModelMap map,int foodId){

        //业务方法
        Foodinfo list= foodrinfoService.findById(foodId);

        //保存数据
        map.addAttribute("food",list);

        //转发
        return "find";  //find.jsp
    }



    @RequestMapping("/edit")
    public String edit(ModelMap map,int foodId){

        //业务方法
        Foodinfo list= foodrinfoService.findById(foodId);

        //保存数据
        map.addAttribute("food",list);

        //转发
        return "update";  //update.jsp
    }



    @RequestMapping("/add")
    public String add(Foodinfo foodinfo){
        //业务方法
        int count= foodrinfoService.insert(foodinfo);
        //转发
        return "redirect:/list";  //直接跳转到list
    }


    @RequestMapping("/update")
    public String update(Foodinfo foodinfo){
        //业务方法
        int count= foodrinfoService.update(foodinfo);
        //转发
        return "redirect:/list";  //直接跳转到list
    }


    @RequestMapping("/del")
    public String del(int foodId){
        //业务方法
        int count= foodrinfoService.delete(foodId);
        //转发
        return "redirect:/list";  //直接跳转到list
    }


    //list1.jsp
//    @RequestMapping("/list")
//    public String list(ModelMap map,Parames parame){
//
//        //业务方法
//        PageInfo<Userinfo> pageInfo= userinfoService.getPageInfo(parame);
//
//        //保存数据
//        map.addAttribute("pageInfo",pageInfo);
//
//        //转发
//        return "list";  //list.jsp
//    }


    @RequestMapping("/list")
    public String list(ModelMap map, Parames parame, Foodinfo foodinfo){

        //业务方法
        PageInfo<Foodinfo> pageInfo= foodrinfoService.findName(foodinfo,parame);

        //保存数据
        map.addAttribute("pageInfo",pageInfo);

        //用户数据
        map.addAttribute("foodinfo",foodinfo);

        //转发
        return "list";  //list.jsp
    }


}
